home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Nebula 2
/
Nebula Two.iso
/
SourceCode
/
PriorityQueue
/
queuetest.m
< prev
next >
Wrap
Text File
|
1995-06-12
|
3KB
|
138 lines
/* NAME:
** QueueTest.m
**
** COPYRIGHT 1992 BY ONYSCHUK AND ASSOCIATES
** ALL RIGHTS RESERVED.
**
** REVISION HISTORY:
** Sun Aug 23 21:10:26 EDT 1992 Mark Onyschuk
** Starting point
**
** DESCRIPTION:
** Program to demonstrate and put the PriorityQueue class
** to the test.
**
** DISCLAIMER:
** This is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as
** published by the Free Software Foundation; either version
** 1, or (at your option) any later version.
**
** This program is distributed in the hope that it will be
** useful, but WITHOUT ANY WARRANTY; without even the implied
** warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
** PURPOSE. See the GNU General Public License for more
** details.
**
** You should have received a copy of the GNU General Public
** License along with this program; if not, write to the Free
** Software Foundation, Inc., 675 Mass Ave, Cambridge, MA
** 02139, USA.
*/
#define NELEM 10
#import "PriorityQueue.h"
void prioritize(void)
{
int i;
id queue;
id obj;
unsigned int priority;
queue = [[PriorityQueue alloc] init];
printf("Queueing and dequeueing Objects:\n\n");
for (i = NELEM; i > 0; i--)
{
obj = [[Object alloc] init];
priority = random() % NELEM;
printf("Queueing object %p with priority %d\n", obj, priority);
[queue addObject:obj withPriority:priority];
}
printf("\n");
for (i = NELEM; i > 0; i--)
{
obj = [queue removeObject];
printf("Dequeued object %p\n", obj);
}
}
void copyqueue(void)
{
int i;
id queue;
id copyA;
id copyB;
id copyC;
id copyD;
id temp;
id obj;
unsigned int priority;
queue = [[PriorityQueue alloc] init];
printf("Copying Objects:\n\n");
for (i = NELEM; i > 0; i--)
{
obj = [[Object alloc] init];
priority = random() % NELEM;
printf("Queueing object %p with priority %d\n", obj, priority);
[queue addObject:obj withPriority:priority];
}
printf("Copying queue to copyA, copyB, copyC, and copyD.\n");
copyA = [queue copy];
copyB = [queue copy];
copyC = [queue copy];
copyD = [queue copy];
for (i = NELEM; i > 0; i--)
{
priority = [queue highestPriority];
obj = [queue removeObject];
printf("Dequeued object %p (orig.) with priority %d\n", obj, priority);
}
for (i = NELEM; i > 0; i--)
{
priority = [copyA highestPriority];
obj = [copyA removeObject];
printf("Dequeued object %p (copyA) with priority %d\n", obj, priority);
}
printf("copyB %s copyC\n", ([copyB isEqual:copyC]) ? "==" : "!=");
printf("removing last item from copyD\n");
[copyD removeObject];
printf("copyC %s copyD\n", ([copyC isEqual:copyD]) ? "==" : "!=");
}
void main(void)
{
prioritize();
printf("\n");
copyqueue();
}